<template>
    <div :class="className" :style="{height:height,width:width}"/>
</template>

<script>
import echarts from "echarts";
//require('echarts/theme/macarons'); // echarts theme
import resize from "./mixins/resize";

const animationDuration = 1000;
export default {
    mixins: [resize],
    props: {
        className: {
            type: String,
            default: "chart"
        },
        width: {
            type: String,
            default: "100%"
        },
        height: {
            type: String,
            default: "260px"
        }
    },
    data() {
        return {
            chart: null
        };
    },
    mounted() {
        this.$nextTick(() => {
            this.initChart();
        });
    },
    beforeDestroy() {
        if (!this.chart) {
            return;
        }
        this.chart.dispose();
        this.chart = null;
    },
    methods: {
        initChart() {
            this.chart = echarts.init(this.$el, "macarons");

            this.chart.setOption({
                tooltip: {
                    trigger: "item",
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                grid: {
                    top: 80,
                    left: "2%",
                    right: "2%",
                    bottom: "3%",
                    containLabel: true
                },
                legend: {
                    data: ['货车','客车','单机','NXN3车辆','NJ2车辆'],
                    textStyle: {
                        color: '#fff'
                    },
                    width : 200
                },
                series: [
                    {
                        name: "车辆类型",
                        type: "pie",
                        radius: [30, 60],
                        center: ["35%", "58%"],
                        roseType: "radius",
                        label: {
                            show: false
                        },
                        data: [
                            { value: 10, name: "货车" },
                            { value: 12, name: "客车" },
                            { value: 15, name: "单机" }
                        ]
                    },
                    {
                        name: "机车类型",
                        type: "pie",
                        radius: [30, 60],
                        center: ["75%", "58%"],
                        roseType: "area",
                        label: {
                            show: false
                        },
                        data: [
                            { value: 22, name: "NXN3车辆" },
                            { value: 12, name: "NJ2车辆" }
                        ]
                    }
                ]
            });
        }
    }
};
</script>
